package com.slfx.open.api.sdk.utils;

import java.io.UnsupportedEncodingException;
import java.util.*;

/**
 * @author slfx
 * @create 2021/2/23 11:06
 */

public class Common {


    /**
     * 拼接符号
     *
     * @param params
     * @return
     */
    public static String forInSpiry(Map params, String appId, String timeStamp) throws UnsupportedEncodingException {
        List<String> keys = new ArrayList<String>(params.keySet());
        Collections.sort(keys);
        String result = "";
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = (String) params.get(key);
//            value = URLEncoder.encode(value, "UTF-8");
            if (i == keys.size() - 1) {//拼接时，不包括最后一个&字符
                result = result + key + "=" + value;
            } else {
                result = result + key + "=" + value + "&";
            }
        }

        result = "appId=" + appId + "&" + result;
        result = result + "&timeStamp=" + timeStamp;

        return result;
    }
}
